<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属银行" prop="tableName">
        <el-select v-model="queryParams.tableName" placeholder="请选择所属银行" clearable >
          <el-option label="银联代扣" value="ecs_yee_pay_withholding" />
          <el-option label="绑卡代扣" value="ecs_yeepay_withhold" />
        </el-select>
      </el-form-item>

      <el-form-item label="二级商户号" prop="subMerchantId">
        <el-input
          v-model="queryParams.subMerchantId"
          placeholder="请输入二级商户号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现时间">
        <el-date-picker clearable
                        v-model="dateRange"
                        type="daterange"
                        range-separator="至"
                        value-format="yyyy-MM-dd"
                        :picker-options="pickerOptions"
                        start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结算状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择结算状态" clearable >
          <el-option label="未结算" :value="0" />
          <el-option label="已结算" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ecs:withholdingRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="withholdingRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="提现id" align="center" prop="withdrawId" min-width="150"/>
      <el-table-column label="店铺名称" align="center" prop="shopName" min-width="150"/>
      <el-table-column label="所属银行" align="center" prop="tableName" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.tableName === 'ecs_pay_ease'">蓝海银行</span>
          <span v-else-if="scope.row.tableName === 'ecs_yee_pay'">商业银行</span>
          <span v-else-if="scope.row.tableName === 'ecs_baofu_merchant'">苏商/华通</span>
          <span v-else-if="scope.row.tableName === 'ecs_yee_pay_withholding'">银联代扣</span>
          <span v-else-if="scope.row.tableName === 'ecs_yeepay_withhold'">绑卡代扣</span>
        </template>
      </el-table-column>
      <el-table-column label="二级商户号" width="120" align="center" prop="subMerchantId"/>
      <el-table-column label="提现账账号" align="center" prop="settleAccount" min-width="120"/>
      <el-table-column label="提现金额" align="center"  prop="amount" min-width="120"/>
      <el-table-column label="提现时间" align="center"  prop="launchTime" min-width="160" />
      <el-table-column label="到账时间" align="center"  prop="withdrawTime" min-width="160" />
      <el-table-column label="是否结算" align="center" min-width="80" prop="tableName">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 1">已结算</span>
          <span v-else>未结算</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" min-width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-more-outline"
            @click="handleWithholdingWithhold(scope.row)"
            v-hasPermi="['ecs:withholdingRecord:list']"
          >抽佣记录</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="抽佣记录" :visible.sync="open" width="85%" append-to-body>
      <withholdingWithhold v-if="open" :withdrawId="form.withdrawId"></withholdingWithhold>
    </el-dialog>
  </div>
</template>

<script>
import { listWithholdingRecord, delWithholdingRecord, addWithholdingRecord, updateWithholdingRecord } from "@/api/ecs/withholdingRecord";
import withholdingWithhold from "@/views/ecs/withholdingWithhold/index.vue"
export default {
  components:{
    withholdingWithhold
  },
  name: "WithholdingRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //日期范围
      dateRange: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入代扣记录表格数据
      withholdingRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopId: null,
        shopName: null,
        agentId: null,
        childAgentId: null,
        platformId: null,
        tableName: null,
        tableNameRequestId: null,
        merchantId: null,
        subMerchantId: null,
        productId: null,
        withdrawId: null,
        amount: null,
        launchTime: null,
        settleAccount: null,
        withdrawTime: null,
        status: null,
      },
      // 表单参数
      form: {
        withdrawId:"",
      },
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询入代扣记录列表 */
    getList() {
      this.loading = true;
      listWithholdingRecord(this.addDateRange(this.queryParams, this.dateRange,"LaunchTime")).then(response => {
        this.withholdingRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 修改按钮操作 */
    handleWithholdingWithhold(row) {
      this.form = row;
      this.open = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWithholdingRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWithholdingRecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除入代扣记录编号为"' + ids + '"的数据项？').then(function() {
        return delWithholdingRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ecs/withholdingRecord/export', {
        ...this.queryParams
      }, `withholdingRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
